<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 17-7-17
 * Time: 下午2:45
 */

namespace Actions;

use Data\Order_for_foods_DAO;
use Data\Order_form_DAO;
use Data\Food_DAO;
use Data\Reminder_order_form_DAO;
use Utils\SysUtils;

class RestaurantReminder extends BaseAction
{
    public function doAction() {
        parent::doAction();
        // 催单id
        $reminder_id = (int)$this->data[REMINDER_ID];
        // 催单记录
        $reminder_record = Reminder_order_form_DAO::getRecord($reminder_id);
        if (!$reminder_record) {
            return $this->SendErrMsg("没有此催单记录");
        }
        // 订单id
        $order_form_id = $reminder_record->getORDER_FORM_ID();
        $order_form_record = Order_form_DAO::getRecord($order_form_id);
        if (!$order_form_record) {
            return $this->SendErrMsg("错误，没有此订单信息");
        }
        // 商家id
        $restaurant_id = $order_form_record->getRESTAURANT_ID();
        // 订单中商品信息
        $order_for_food_list = Order_for_foods_DAO::getListByOrderFormId($order_form_id);
        foreach ($order_for_food_list as $key=>$order_for_food_record) {
            $food_id = $order_for_food_record[FOOD_ID];
            $food_name = Food_DAO::getName($food_id);
            $order_for_food_list[$key][FOOD_NAME] = $food_name;
        }
        // 订单全部信息
        $order_info = array(REMINDER_ID=>$reminder_id,ORDER_FORM_INFO=>$order_form_record->getArray(),ORDER_FOR_FOOD_INFO=>$order_for_food_list);
        $sendData = array( ORDER_INFO => $order_info);
        // 推送

        SysUtils::notifyTofFrontEnd($restaurant_id,$sendData,EVENT_RESTAURANT_REMINDER);

        $this->ResponseDataToCurrentClient();
    }
}